<?php
namespace Emos;

class Common {
    public static $developerMode = false;
    
    public static function setDeveloperMode($developerMode = true) {
        self::$developerMode = $developerMode;
    }    
    
    protected static $translations = array();    
    
    static public function plain($text) {
        return htmlspecialchars($text, ENT_QUOTES);        
    }
    
    static public function t($text, array $params=array()) {
        if(!self::$translations) {
            self::$translations = include(__DIR__.'/../../i18n/ru.php');
        }
        
        $result = @self::$translations[$text];
        if($result == null) {
            $result = "*{$text}";
            foreach($params as $k => $v) {            
                $result .= " | {$k}:{$v}";
            }            
        }
        else {
            $repls = array();
            foreach($params as $k => $v) {            
                $repls[('{'.$k.'}')] = $v;
            }
            $result = strtr($result, $repls);            
        }        
        
        return $result;        
    }   
    
    static public function render($_templateFile, $_params) {
        extract($_params);
        
        ob_start();
        include $_templateFile;
        return ob_get_clean();
    }
}